package jdbc;

import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class JdbcTest5 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("查询第几页，一页多大？");
        int pageNo = sc.nextInt();
        int pageSize = sc.nextInt();

        String sql = "select * from s_student order by stuno desc limit ?,?";
        Connection connection = DBUtil.getConnection();

        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,(pageNo-1)*pageSize);
            ps.setInt(2,pageSize);
            rs = ps.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getLong("stuno") + "," + rs.getString("sname") + "," + rs.getDate("enterdate") + "," + rs.getString("telephone"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, ps, connection);
        }

    }
}
